﻿<?php require_once('Connections/satphp.php'); ?>
<?php
function erro(){include "error-page.html";exit;} 

if (!isset($_GET['idturma']) || $_GET['idturma'] == '')erro();
else $idturma = $_GET['idturma'];

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$idaluno = 3;

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO forum (idturma, idaluno, titulo, mensagem, idpai) VALUES (%s, %s, %s, %s, %s)",
                       GetSQLValueString($_GET['idturma'], "int"),
                       GetSQLValueString($idaluno, "int"),
                       GetSQLValueString($_POST['titulo'], "text"),
                       GetSQLValueString($_POST['mensagem'], "text"),
                       GetSQLValueString(0, "int"));

  mysql_select_db($database_satphp, $satphp);
  $Result1 = mysql_query($insertSQL, $satphp) or die(mysql_error());

  $insertGoTo = "forum.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Novo post | SATPHP</title>
<script type="text/javascript" src="javascript/editortexto.js"></script>
<script type="text/javascript">
	//<![CDATA[
    bkLib.onDomLoaded(function() { nicEditors.allTextAreas() });
    //]]>
</script>
</head>

<body>
<form action="?idturma=<?php echo $idturma; ?>" method="post" name="form1" id="form1">
  <table align="center">
    <tr>
    <tr>
      <td>Título:</td>
    </tr>
      <td><input name="titulo" type="text" style="width: 300px;" /></td>
    </tr>
    <tr>
      <td>Conteúdo:</td>
    </tr>
    <tr>
      <td><textarea style="width: 500px; height: 200px;" name="mensagem"></textarea></td>
    </tr>
    <tr>
      <td align="right"><input type="submit" value="Enviar post" /></td>
    </tr>
  </table>
   <input type="hidden" name="MM_insert" value="form1" />
</form>
</body>
</html>